package dashboard;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class MilestoneController {
	
	private Milestone milestone;
	
	public MilestoneController()
	{
		milestone = new Milestone();
	}

	public void addMilestone(User user) 
	{

		user.addMilestone(milestone);	
		UserRegistry.getInstance().addUser(user);
		clear();
	}
	
	public void setAction(String action)
	{
		milestone.setAction(action);
	}
	public List<String> setCourses(List<Long> courses)
	{
		List<String> errors = new ArrayList<String>();
		
		milestone.setCourses(courses);
		if(courses.isEmpty())	errors.add("No course(s) given.");
		
		return errors;
	}
	
	public List<String> setTypes(String[] types)
	{
		List<String> errors = new ArrayList<String>();
		
		List<String> type = new ArrayList<String>();
		if(types != null && types.length != 0)
		{
			for(String str: types)
			{
				type.add(str);
			}
			milestone.setTypes(type);
		}
		if(type.isEmpty())	errors.add("No type given.");
		
		return errors;
	}
	public List<String> setDates(Date start, Date stop)
	{
		List<String> errors = new ArrayList<String>();
		Date now = new Date();
		milestone.setStart(start);
		if(now.getTime() - start.getTime() > (3600 * 1000 * 24)){
			if(start.before(now)) errors.add("The start date cannot be before now.");
		}
		milestone.setEnd(stop);
		if(stop.before(start)) errors.add("The stop date cannot be before the start date");
		if(stop.equals(start)) errors.add("The start and stop date cannot be the same.");
		
		return errors;
	}
	public List<String> setGoal(double goal)
	{
		List<String> errors = new ArrayList<String>();
		
		
		if(goal<=0)	{			errors.add("Not a number");}
		else{
		milestone.setGoal(goal);
		}
		
		return errors;
	}
	public void clear()
	{
		milestone = new Milestone();
	}
	public Milestone getMilestone()
	{
		return milestone;
	}

}